if host_machine.system() == 'windows' or cpp.links(
  'int main(){__sync_synchronize();}',
)
  atomic_dep = dependency(
    '',
    required: false,
  )
else
  atomic_dep = cpp.find_library(
    'atomic',
    required: false,
  )
endif

utfcpp_dep = dependency('utf8cpp')

install_headers(
  'ape/apefile.h',
  'ape/apefooter.h',
  'ape/apeitem.h',
  'ape/apeproperties.h',
  'ape/apetag.h',
  'asf/asfattribute.h',
  'asf/asffile.h',
  'asf/asfpicture.h',
  'asf/asfproperties.h',
  'asf/asftag.h',
  'dsdiff/dsdiffdiintag.h',
  'dsdiff/dsdifffile.h',
  'dsdiff/dsdiffproperties.h',
  'dsf/dsffile.h',
  'dsf/dsfproperties.h',
  'flac/flacmetadatablock.h',
  'flac/flacfile.h',
  'flac/flacpicture.h',
  'flac/flacproperties.h',
  'it/itfile.h',
  'it/itproperties.h',
  'mod/modfile.h',
  'mod/modfilebase.h',
  'mod/modproperties.h',
  'mod/modtag.h',
  'mp4/mp4atom.h',
  'mp4/mp4coverart.h',
  'mp4/mp4item.h',
  'mp4/mp4properties.h',
  'mp4/mp4file.h',
  'mp4/mp4tag.h',
  'mpc/mpcfile.h',
  'mpc/mpcproperties.h',
  'mpeg/id3v1/id3v1genres.h',
  'mpeg/id3v1/id3v1tag.h',
  'mpeg/id3v2/frames/attachedpictureframe.h',
  'mpeg/id3v2/frames/commentsframe.h',
  'mpeg/id3v2/frames/eventtimingcodesframe.h',
  'mpeg/id3v2/frames/generalencapsulatedobjectframe.h',
  'mpeg/id3v2/frames/ownershipframe.h',
  'mpeg/id3v2/frames/popularimeterframe.h',
  'mpeg/id3v2/frames/privateframe.h',
  'mpeg/id3v2/frames/synchronizedlyricsframe.h',
  'mpeg/id3v2/frames/tableofcontentsframe.h',
  'mpeg/id3v2/frames/textidentificationframe.h',
  'mpeg/id3v2/frames/unsynchronizedlyricsframe.h',
  'mpeg/id3v2/frames/urllinkframe.h',
  'mpeg/id3v2/frames/chapterframe.h',
  'mpeg/id3v2/frames/podcastframe.h',
  'mpeg/id3v2/frames/relativevolumeframe.h',
  'mpeg/id3v2/frames/uniquefileidentifierframe.h',
  'mpeg/id3v2/frames/unknownframe.h',
  'mpeg/id3v2/id3v2footer.h',
  'mpeg/id3v2/id3v2synchdata.h',
  'mpeg/id3v2/id3v2.h',
  'mpeg/id3v2/id3v2extendedheader.h',
  'mpeg/id3v2/id3v2frame.h',
  'mpeg/id3v2/id3v2framefactory.h',
  'mpeg/id3v2/id3v2header.h',
  'mpeg/id3v2/id3v2tag.h',
  'mpeg/mpegfile.h',
  'mpeg/mpegheader.h',
  'mpeg/mpegproperties.h',
  'mpeg/xingheader.h',
  'ogg/flac/oggflacfile.h',
  'ogg/opus/opusfile.h',
  'ogg/opus/opusproperties.h',
  'ogg/speex/speexfile.h',
  'ogg/speex/speexproperties.h',
  'ogg/vorbis/vorbisfile.h',
  'ogg/vorbis/vorbisproperties.h',
  'ogg/oggfile.h',
  'ogg/oggpage.h',
  'ogg/oggpageheader.h',
  'ogg/xiphcomment.h',
  'riff/aiff/aifffile.h',
  'riff/aiff/aiffproperties.h',
  'riff/rifffile.h',
  'riff/wav/infotag.h',
  'riff/wav/wavfile.h',
  'riff/wav/wavproperties.h',
  's3m/s3mfile.h',
  's3m/s3mproperties.h',
  'shorten/shortenfile.h',
  'shorten/shortenproperties.h',
  'shorten/shortentag.h',
  'taglib_export.h',
  'toolkit/tdebuglistener.h',
  'toolkit/taglib.h',
  'toolkit/tbytevector.h',
  'toolkit/tbytevectorlist.h',
  'toolkit/tbytevectorstream.h',
  'toolkit/tfile.h',
  'toolkit/tfilestream.h',
  'toolkit/tiostream.h',
  'toolkit/tlist.h',
  'toolkit/tlist.tcc',
  'toolkit/tmap.h',
  'toolkit/tmap.tcc',
  'toolkit/tpropertymap.h',
  'toolkit/tstring.h',
  'toolkit/tstringlist.h',
  'trueaudio/trueaudiofile.h',
  'trueaudio/trueaudioproperties.h',
  'wavpack/wavpackfile.h',
  'wavpack/wavpackproperties.h',
  'xm/xmfile.h',
  'xm/xmproperties.h',
  'audioproperties.h',
  'fileref.h',
  'tag.h',
  subdir: 'taglib',
)

taglib_includes = include_directories(
  '.',
  'ape',
  'asf',
  'dsdiff',
  'dsf',
  'flac',
  'it',
  'mod',
  'mp4',
  'mpc',
  'mpeg',
  'mpeg/id3v1',
  'mpeg/id3v2',
  'mpeg/id3v2/frames',
  'ogg',
  'ogg/flac',
  'ogg/opus',
  'ogg/speex',
  'ogg/vorbis',
  'riff',
  'riff/aiff',
  'riff/wav',
  's3m',
  'shorten',
  'toolkit',
  'trueaudio',
  'wavpack',
  'xm',
)

taglib = library(
  'tag',
  'ape/apefile.cpp',
  'ape/apefooter.cpp',
  'ape/apeitem.cpp',
  'ape/apeproperties.cpp',
  'ape/apetag.cpp',
  'asf/asfattribute.cpp',
  'asf/asffile.cpp',
  'asf/asfpicture.cpp',
  'asf/asfproperties.cpp',
  'asf/asftag.cpp',
  'dsdiff/dsdiffdiintag.cpp',
  'dsdiff/dsdifffile.cpp',
  'dsdiff/dsdiffproperties.cpp',
  'dsf/dsffile.cpp',
  'dsf/dsfproperties.cpp',
  'flac/flacfile.cpp',
  'flac/flacmetadatablock.cpp',
  'flac/flacpicture.cpp',
  'flac/flacproperties.cpp',
  'flac/flacunknownmetadatablock.cpp',
  'it/itfile.cpp',
  'it/itproperties.cpp',
  'mod/modfile.cpp',
  'mod/modfilebase.cpp',
  'mod/modproperties.cpp',
  'mod/modtag.cpp',
  'mp4/mp4atom.cpp',
  'mp4/mp4coverart.cpp',
  'mp4/mp4file.cpp',
  'mp4/mp4item.cpp',
  'mp4/mp4itemfactory.cpp',
  'mp4/mp4properties.cpp',
  'mp4/mp4tag.cpp',
  'mpc/mpcfile.cpp',
  'mpc/mpcproperties.cpp',
  'mpeg/id3v1/id3v1genres.cpp',
  'mpeg/id3v1/id3v1tag.cpp',
  'mpeg/id3v2/frames/attachedpictureframe.cpp',
  'mpeg/id3v2/frames/chapterframe.cpp',
  'mpeg/id3v2/frames/commentsframe.cpp',
  'mpeg/id3v2/frames/eventtimingcodesframe.cpp',
  'mpeg/id3v2/frames/generalencapsulatedobjectframe.cpp',
  'mpeg/id3v2/frames/ownershipframe.cpp',
  'mpeg/id3v2/frames/podcastframe.cpp',
  'mpeg/id3v2/frames/popularimeterframe.cpp',
  'mpeg/id3v2/frames/privateframe.cpp',
  'mpeg/id3v2/frames/relativevolumeframe.cpp',
  'mpeg/id3v2/frames/synchronizedlyricsframe.cpp',
  'mpeg/id3v2/frames/tableofcontentsframe.cpp',
  'mpeg/id3v2/frames/textidentificationframe.cpp',
  'mpeg/id3v2/frames/uniquefileidentifierframe.cpp',
  'mpeg/id3v2/frames/unknownframe.cpp',
  'mpeg/id3v2/frames/unsynchronizedlyricsframe.cpp',
  'mpeg/id3v2/frames/urllinkframe.cpp',
  'mpeg/id3v2/id3v2extendedheader.cpp',
  'mpeg/id3v2/id3v2footer.cpp',
  'mpeg/id3v2/id3v2frame.cpp',
  'mpeg/id3v2/id3v2framefactory.cpp',
  'mpeg/id3v2/id3v2header.cpp',
  'mpeg/id3v2/id3v2synchdata.cpp',
  'mpeg/id3v2/id3v2tag.cpp',
  'mpeg/mpegfile.cpp',
  'mpeg/mpegheader.cpp',
  'mpeg/mpegproperties.cpp',
  'mpeg/xingheader.cpp',
  'ogg/flac/oggflacfile.cpp',
  'ogg/oggfile.cpp',
  'ogg/oggpage.cpp',
  'ogg/oggpageheader.cpp',
  'ogg/opus/opusfile.cpp',
  'ogg/opus/opusproperties.cpp',
  'ogg/speex/speexfile.cpp',
  'ogg/speex/speexproperties.cpp',
  'ogg/vorbis/vorbisfile.cpp',
  'ogg/vorbis/vorbisproperties.cpp',
  'ogg/xiphcomment.cpp',
  'riff/aiff/aifffile.cpp',
  'riff/aiff/aiffproperties.cpp',
  'riff/rifffile.cpp',
  'riff/wav/infotag.cpp',
  'riff/wav/wavfile.cpp',
  'riff/wav/wavproperties.cpp',
  's3m/s3mfile.cpp',
  's3m/s3mproperties.cpp',
  'shorten/shortenfile.cpp',
  'shorten/shortenproperties.cpp',
  'shorten/shortentag.cpp',
  'toolkit/tbytevector.cpp',
  'toolkit/tbytevectorlist.cpp',
  'toolkit/tbytevectorstream.cpp',
  'toolkit/tdebug.cpp',
  'toolkit/tdebuglistener.cpp',
  'toolkit/tfile.cpp',
  'toolkit/tfilestream.cpp',
  'toolkit/tiostream.cpp',
  'toolkit/tpicturetype.cpp',
  'toolkit/tpropertymap.cpp',
  'toolkit/tstring.cpp',
  'toolkit/tstringlist.cpp',
  'toolkit/tvariant.cpp',
  'toolkit/tversionnumber.cpp',
  'toolkit/tzlib.cpp',
  'trueaudio/trueaudiofile.cpp',
  'trueaudio/trueaudioproperties.cpp',
  'wavpack/wavpackfile.cpp',
  'wavpack/wavpackproperties.cpp',
  'xm/xmfile.cpp',
  'xm/xmproperties.cpp',
  'audioproperties.cpp',
  'fileref.cpp',
  'tag.cpp',
  'tagunion.cpp',
  'tagutils.cpp',
  include_directories: [taglib_includes, '..'],
  dependencies: [atomic_dep, utfcpp_dep, zlib_dep],
  cpp_args: '-DHAVE_CONFIG_H',
  install: true,
  version: '2.0.2',
)

pkg = import('pkgconfig')
pkg.generate(
  taglib,
  name: 'taglib',
  subdirs: 'taglib',
)

taglib_dep = declare_dependency(
  include_directories: taglib_includes,
  link_with: taglib,
)
